class Role():
    def __init__(self, role_name, sex, blood_volume, equip):
        self.role_name = role_name
        self.sex = sex
        self.blood_volume = blood_volume
        self.equip = equip
        self.room = None
    def attach(self, attack_role):
        if self.room == role_dict[attack_role].room:
            attack_count = input("请输入您要攻击的次数:")
            while not attack_count.isdigit():
                attack_count = input("输入有误，请重新输入您要攻击的次数:")
            if role_dict[attack_role].equip != '防弹衣':
                n = 10
            else:
                n = 5
            if role_dict[attack_role].blood_volume <= n * int(attack_count):
                role_dict.pop(attack_role)
                print(f"{attack_role}血量为0,{self.role_name}胜利")
            else:
                role_dict[attack_role].blood_volume -= n * int(attack_count)
                print(f"{attack_role}受到攻击、血量减少{n * int(attack_count)},剩余{role_dict[attack_role].blood_volume}")
        else:
            print(f"{self.role_name}和{attack_role}不在同一个房间无法攻击")


class Room():
    def __init__(self, room_name):
        self.room_name = room_name
        self.list = []
    def add_role(self, role_name, room_name):
        if len(self.list) < 2:
            while True:
                if role_name not in role_dict:
                    role_name = input("该用户不存在、请重新输入:")
                elif role_name in self.list:
                    role_name = input("该用户已加入该房间、请重新输入:")
                elif role_dict[role_name].room:
                    role_name = input(f"该用户已加入{role_dict[role_name].room}房间、请重新输入:")
                else:
                    self.list.append(role_name)
                    role_dict[role_name].room = room_name
                    print(f"{role_name}加入{room_name}房间成功,该房间里的角色有{self.list}")
                    break
        else:
            print(f"{room_name}房间已满、该房间里的角色有{self.list}")


option = ''
room_dict = {}
role_dict = {}
roles = []
print("欢迎来到回合制对战游戏".center(20,'*'))
while option != 'quit' and option != '5':
    print("       1、创建角色\n       2、创建房间\n       3、加入房间\n       4、开始游戏\n       5、输入quit退出")
    option = input("请输入你的选择：")
    if option == '1':
        role_name = input("请输入您要创建的角色名字:")
        while role_name in role_dict:
            role_name = input("该角色名已存在、请重新输入:")
        sex = input("请输入您要创建的角色性别:")
        blood_volume = 100
        print("装备表".center(20,'*'))
        equip = input("1、防弹衣(正常被攻击-10滴血、有防弹衣-5滴血)\n2、跳过\n请输入您要购买的装备:")
        if equip == '1':
            equip = "防弹衣"
            role_dict[role_name] = Role(role_name, sex, blood_volume, equip)
            print("角色创建成功")
        else:
            equip = ""
            role_dict[role_name] = Role(role_name, sex, blood_volume, equip)
            print("角色创建成功")
    elif option == '2':
        room_name = input("请输入您要创建的房间名字:")
        while room_name in room_dict:
            room_name = input("该房间已存在、请重新输入:")
        if room_name != 'quit':
            room_dict[room_name] = Room(room_name)
            print("创建房间成功")
        else:
            print("退出成功")
            break
    elif option == '3':
        print(f"已创建的房间{room_dict.keys()},已创建的角色{role_dict.keys()}")
        room_name = input("请输入您要加入的房间名字:")
        while room_name not in room_dict and room_name != 'quit':
            room_name = input("该房间不存在,请重新输入:")
        role_name = input("请输入要加入该房间的角色名称:")
        while role_name not in role_dict and role_name != 'quit':
            role_name = input("该用户不存在、请重新输入:")
        if role_name != 'quit' and room_name != 'quit':
            room_dict[room_name].add_role(role_name, room_name)
        else:
            print("退出成功")
            break
    elif option == '4':
        role_name = input("请输入您要使用的角色:")
        while role_name not in role_dict:
            role_name = input("该角色名不存在、请重新输入:")
        attack_role = input("请输入您要攻击的对象:")
        while attack_role not in role_dict:
            attack_role = input("该角色名不存在、请重新输入:")
        while role_name != 'quit' and attack_role != 'quit':
            if role_name != attack_role:
                role_dict[role_name].attach(attack_role)
                role_name = input("请输入您要使用的角色:")
                attack_role = input("请输入您要攻击的对象:")
            else:
                print("不能攻击自己")
                role_name = input("请输入您要使用的角色:")
                attack_role = input("请输入您要攻击的对象:")
    elif option.lower() != 'quit' or option != '5':
        option = input("输入有误，请重新输入")
print("退出成功")
